package cn.demo.d03;

import java.util.*;

public class Demo05 {
    public static void main(String[] args) {
        // demo01();
        // demo02();
        // demo03();
        // demo04();
        demo05();
    }

    /* 需求
        定义一个Map集合，键用表示省份名称province，值表示市city，但是市会有多个。
        添加完毕后，遍历结果格式如下：
                江苏省 = 南京市，扬州市，苏州市，无锡市，常州市
                湖北省 = 武汉市，孝感市，十堰市，宜昌市，鄂州市
                河北省 = 石家庄市，唐山市，邢台市，保定市，张家口市*/
    private static void demo05() {
        Map<String,List<String>> map = new HashMap<>();
        List<String> list1 = new ArrayList<>();
        Collections.addAll(list1,"南京市", "扬州市", "苏州市", "无锡市", "常州市");
        map.put("江苏省",list1);
        List<String> list2 = new ArrayList<>();
        Collections.addAll(list2,"武汉市", "孝感市", "十堰市", "宜昌市", "鄂州市");
        map.put("湖北省",list2);
        List<String> list3 = new ArrayList<>();
        Collections.addAll(list3,"石家庄市", "唐山市", "邢台市", "保定市", "张家口市");
        map.put("河北省",list3);
        Set<Map.Entry<String, List<String>>> entries = map.entrySet();
        entries.forEach(entry -> {
            System.out.print(entry.getKey() + " = ");
            StringJoiner sj = new StringJoiner("，");
            entry.getValue().forEach(sj::add);
            System.out.println(sj);
        });
    }

    /* 班级里有5个学生
        要求：
        被点到的学生不会再被点到。
        但是如果班级中所有的学生都点完了，需要重新开启第二轮点名。*/
    private static void demo04() {
        List<String> list = new ArrayList<>();
        Collections.addAll(list, "范闲","范建","范统","杜子腾","杜琦燕","宋合泛","侯笼藤","朱益群","朱穆朗玛峰","袁明媛");
        List<String> list2 = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 10; i++) {
            System.out.println("=========第" + i + "轮点名开始了======================");
            while (!list.isEmpty()){
                int index = r.nextInt(list.size());
                String name = list.remove(index);
                list2.add(name);
                System.out.print(name+"  ");
            }
            System.out.println();
            list.addAll(list2);
            list2.clear();
        }
    }

    /* 班级里有N个学生
        要求：
        70%的概率随机到男生
        30%的概率随机到女生

        "范闲","范建","范统","杜子腾","宋合泛","侯笼藤","朱益群","朱穆朗玛峰",
        "杜琦燕","袁明媛","李猜","田蜜蜜",
        */
    private static void demo03() {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,1,1,1,1,1,1,0,0,0);
        List<String> boyList = new ArrayList<>();
        List<String> girlList = new ArrayList<>();
        Collections.addAll(boyList,"范闲","范建","范统","杜子腾","宋合泛","侯笼藤","朱益群","朱穆朗玛峰");
        Collections.addAll(girlList,"杜琦燕","袁明媛","李猜","田蜜蜜");
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            int index = list.get(random.nextInt(list.size()));
            System.out.print(index + "  ");
            if (index == 1){
                int i1 = random.nextInt(boyList.size());
                System.out.println(boyList.get(i1));
            }else{
                int i2 = random.nextInt(girlList.size());
                System.out.println(girlList.get(i2));
            }
        }
    }

    /* 班级里有N个学生，学生属性:姓名，年龄，性别。
       实现随机点名器。*/
    private static void demo02() {
        List<String> list = new ArrayList<>();
        Collections.addAll(list, "范闲","范建","范统","杜子腾","杜琦燕","宋合泛","侯笼藤","朱益群","朱穆朗玛峰","袁明媛");
        for (int i = 0; i < 10; i++) {
            Collections.shuffle(list);
            System.out.println(list.get(0));
        }
    }

    public static void demo01() {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,100,200,180,110,230,111);
        System.out.println(list);
        // Collections.sort(list,((o1, o2) -> Integer.compare(o2,o1)));
        // list.sort(((o1, o2) -> Integer.compare(o2, o1)));
        list.sort(((o1, o2) -> o2 - o1));
        System.out.println(list);
    }
}
